package day04.text02;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8888);

        OutputStream outputStream = socket.getOutputStream();

        System.out.println("1：/user ");
        System.out.println("2：/order");
        System.out.println("3:/cart");

        Scanner sc = new Scanner(System.in);
        String id = sc.next();
        switch (id){
            case "1":
                outputScanner(socket, outputStream, id);
                break;
            case "2":
                outputScanner(socket, outputStream, id);
                break;
            case "3":
                outputScanner(socket, outputStream, id);
                break;
            default:
                System.out.println("你输入的有误");
                break;
        }



    }

    private static void outputScanner(Socket socket, OutputStream outputStream, String id) throws IOException {
        ConcurrentHashMap<String ,String> chm = new ConcurrentHashMap<>();
        chm.put("1","/user");
        chm.put("2","/order");
        chm.put("3","/cart");
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream));

        bw.write(chm.get(id));
        bw.flush();
        bw.close();
        socket.close();
    }
}
